package org.ysh.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ysh.core.annotation.ResourceEx;
import org.ysh.service.ResourceService;
import org.ysh.vo.IndexInfoVo;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Controller
public class HomeController {

    @Resource
    ResourceService resourceService;

    @RequestMapping("/index")
    public String index(){
        return "index";
    }


    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 个人空间
     */
    @ResourceEx(name = "个人空间", icon = "fa fa-user", sort = 1, type = 0, code = "userSpace")
    public void userSpace() {
    }

    @ResourceEx(name = "档案收集", icon = "fa fa-user", sort =2 , type = 0, code = "archiveCollect")
    public void archiveCollect() {

    }

    @ResourceEx(name = "档案整理", icon = "fa fa-user", sort = 3, type = 0, code = "archiveArrange")
    public void archiveArrange() {

    }

    @ResourceEx(name = "档案保管", icon = "fa fa-user", sort = 4, type = 0, code = "archiveStore")
    public void archiveStore() {

    }

    @ResourceEx(name = "档案利用", icon = "fa fa-user", sort = 5, type = 0, code = "archiveUtility")
    public void archiveUtility() {

    }

    @ResourceEx(name = "档案统计", icon = "fa fa-bar-chart", sort = 6, type = 0, code = "archiveStatistic")
    public void archiveStatistic() {

    }

    @ResourceEx(name = "系统管理", icon = "fa fa-server", sort = 7, type = 0, code = "system")
    public void systemManage() {

    }

    @RequestMapping("/index/init")
    @ResponseBody
    public IndexInfoVo init() {
        IndexInfoVo indexInfoVo = new IndexInfoVo();
        indexInfoVo.setHomeInfo(IndexInfoVo.buildHomeInfo("首页", "/welcome"));
        indexInfoVo.setLogoInfo(IndexInfoVo.buildLogoInfo("智慧档案管理系统","/","/public/images/logo.png"));
        List<IndexInfoVo.MenuInfo> menuInfos = resourceService.buildMenuInfos();
        IndexInfoVo.MenuInfo root = new IndexInfoVo.MenuInfo();
        root.setTitle("档案资源");
        root.setHref("");
        root.setChild(menuInfos);
        indexInfoVo.setMenuInfo(Collections.singletonList(root));
        return indexInfoVo;
    }
}
